package br.com.agiledev.webscrum.entity;

import static javax.persistence.FetchType.LAZY;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;

import org.hibernate.annotations.ForeignKey;

import br.com.agiledev.webscrum.enumeration.State;

/**
 * Entity implementation class for Entity: Task
 * 
 */
@Entity
@SequenceGenerator(name = "task", sequenceName = "se_task")
public class Task implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "task")
    private Long oid;

    @Column(length = 255)
    private String descricao;

    @ManyToOne(fetch = LAZY, optional = false)
    @ForeignKey(name = "fk_task_item")
    private Item item;

    @Column(nullable = false)
    @Enumerated(EnumType.ORDINAL)
    private State state = State.planned;

    public Task() {
	super();
    }

    public Task(Item item) {
	setItem(item);
    }

    public String getDescricao() {
	return descricao;
    }

    public Item getItem() {
	return item;
    }

    public Long getOid() {
	return oid;
    }

    public void setDescricao(String descricao) {
	this.descricao = descricao;
    }

    public void setItem(Item item) {
	this.item = item;
    }

    public void setOid(Long oid) {
	this.oid = oid;
    }

    @Override
    public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result + ((oid == null) ? 0 : oid.hashCode());
	return result;
    }

    @Override
    public boolean equals(Object obj) {
	if (this == obj)
	    return true;
	if (obj == null)
	    return false;
	Task other = (Task) obj;
	if (oid == null) {
	    if (other.getOid() != null)
		return false;
	} else if (!oid.equals(other.getOid()))
	    return false;
	return true;
    }

    public State getState() {
	return state;
    }

    public void setState(State state) {
	this.state = state;
    }
}
